package com.tfswx.fljdmxyy.api;

import cn.hutool.core.date.DateTime;
import com.tfswx.fljdmxyy.dto.dwgl.*;
import com.tfswx.fljdmxyy.query.dwgl.DwxxQueryParam;
import com.tfswx.fljdmxyy.query.dwgl.DwxxQueryResult;
import com.tfswx.fljdmxyy.query.dwgl.ZzjgQueryParam;
import com.tfswx.fljdmxyy.query.dwgl.ZzjgQueryResult;
import com.tfswx.fljdmxyy.service.DwglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 单位管理
 *
 * @Author 陈文佳
 * @Date 2023/03/24
 */
@Api(tags = "单位管理")
@RequestMapping("api/zzjg")
@RestController
public class DwglController {

    @Resource
    private DwglService dwglService;

    @ApiOperation("新增单位")
    @PostMapping("/addDwxx")
    public DwxxAddOutputDTO addDwxx(@RequestBody @Validated DwxxAddInputDTO dto) {
        return dwglService.addDwxx(dto);
    }

    @ApiOperation("修改单位信息")
    @PostMapping("/updateDwxx")
    public DwxxUpdateOutputDTO updateDwxx(@RequestBody @Validated DwxxUpdateInputDTO dto) {
        return dwglService.updateDwxx(dto);
    }

    @ApiOperation("删除单位")
    @PostMapping("/deleteDwxx")
    public DwxxDeleteOutputDTO deleteDwxx(@RequestBody @Validated DwxxDeleteInputDTO dto) {
        return dwglService.deleteDwxx(dto);
    }

    @ApiOperation("查询单位")
    @PostMapping("/getDwxx")
    public DwxxGetOutputDTO getDwxx(@RequestBody @Validated DwxxGetInputDTO dto) {
        return dwglService.getDwxx(dto);
    }

    @ApiOperation("查询所有单位")
    @PostMapping("/queryDwxx")
    public List<DwxxQueryResult> queryDwxx() {
        return dwglService.queryDwxx();
    }

    @ApiOperation("查询下级单位")
    @PostMapping("/queryDwlb")
    public List<DwxxQueryResult> queryDwlb(@RequestBody @Validated DwxxQueryParam param) {
        return dwglService.queryDwlb(param);
    }

    @ApiOperation("查询单位部门角色人员树（统一业务）")
    @PostMapping("/queryZzjg")
    public List<ZzjgQueryResult> queryZzjg(@RequestBody @Validated ZzjgQueryParam param) {
        return dwglService.queryZzjg(param);
    }

    @ApiOperation("获取服务器系统时间")
    @PostMapping("getServerTime")
    public String getTime() {
        // 主要用于接口请求签名值生成与验证
        return String.valueOf(DateTime.now().getTime());
    }
}
